﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace LibrarySystem
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        private string _persID;

        protected void Page_Load(object sender, EventArgs e)
        {
            _persID = Session["PID"].ToString();

            BusinessLayer.Borrower thisBorrower = BusinessLayer.Borrower.getBorrowerByID(_persID);
            borrowerName.Text = thisBorrower.FirstName + " " + thisBorrower.LastName;           

            List<BusinessLayer.Loan> actList = BusinessLayer.Loan.getActiveLoans(_persID);
            adminBorrowerActiveLoans.DataSource = actList;
            adminBorrowerActiveLoans.DataBind();

            List<BusinessLayer.Loan> histList = BusinessLayer.Loan.getLoanHistory(_persID);
            adminBorrowerHistory.DataSource = histList;
            adminBorrowerHistory.DataBind();
        }

        protected void listItem_ClickedBook(object sender, CommandEventArgs e)
        {
            string itemISBN = e.CommandName.ToString();
            Response.Redirect("adminBookDetail.aspx?isbn=" + itemISBN);
        }

        protected void extendLoanBtn_Click(object sender, CommandEventArgs e)
        {
            string barcode = e.CommandName.ToString();
            BusinessLayer.Loan.extendLoan(_persID, barcode);
            Response.Redirect(Request.RawUrl);
        }
    }
}